import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oktoast/oktoast.dart';
import 'package:wan_android_flutter/pages/home/home_page.dart';
import 'package:wan_android_flutter/route/RouteUtils.dart';
import 'package:wan_android_flutter/route/routes.dart';

/// 设计尺寸
Size get designSize {
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  // 逻辑短边
  final logicalShortestSide =
      firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  // 逻辑长边
  final logicalLongestSide =
      firstView.physicalSize.longestSide / firstView.devicePixelRatio;
  // 缩放比例 designSize越小，元素越大
  const scaleFactor = 0.95;
  // 缩放后的逻辑短边和长边
  return Size(
      logicalShortestSide * scaleFactor, logicalLongestSide * scaleFactor);
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    //toast提示必须为APP的顶层组件
    return OKToast(
        //屏幕适配父组件组件
        child: ScreenUtilInit(
      designSize: designSize, // 设计稿尺寸
      builder: (context, child) {
        // MaterialApp 是 Flutter 应用的根组件，用于配置应用的主题、路由等
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            // 配置应用的主题
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            // 使用种子颜色生成主题
            useMaterial3: true, // 启用 Material 3 设计风格
          ),
          navigatorKey: RouteUtils.navigatorKey,
          onGenerateRoute: Routes.generateRoute,
          // 动态路由生成器，用于根据路由名称生成对应的页面
          initialRoute: RoutePath.tab, // 初始路由，指定应用启动时加载的第一个页面
          //home: HomePage(),  // 如果不需要动态路由，可以直接指定 home 页面
        );
      },
    ));
  }
}
